package com.cy.springcloudalibaba.blockhandlers;

import com.alibaba.cloud.sentinel.rest.SentinelClientHttpResponse;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;

/**
 * @Description: resttemplate调用失败后的熔断降级方法
 * @ClassName: RestTemplateBlockHandler
 * @Author: chenyu
 * @Date: 2025/1/20 10:01
 */
public class RestTemplateBlockHandler {

    /**
     * 限流后处理的方法
     * @param request
     * @param body
     * @param execution
     * @param ex
     * @return com.alibaba.cloud.sentinel.rest.SentinelClientHttpResponse
     * @date 2025/1/20 10:08
     */
    public static SentinelClientHttpResponse blockA(HttpRequest request, byte[] body,
                                                    ClientHttpRequestExecution execution, BlockException ex) {
        System.err.println("block: " + ex.getClass().getCanonicalName());
        return new SentinelClientHttpResponse("custom block info");
    }
}
